That depends on where you are. Some possible choices are
123,456,789 123.456.789 123 456 789
In Canada, UK, and US, commas are used to separate groups of three digits. Other countries use periods or spaces for that purpose.
When the Java virtual machine starts running on a computer, it creates an object called the default locale. This object affects how some methods format data. Here is a program that writes different strings, depending on where it is run.
import java.util.Locale; import java.text.*; class IODemo2 { public static void main ( String[] args ) { int value = 123456789 ; System.out.println( "Default Locale = " + Locale.getDefault() ); DecimalFormat decform = new DecimalFormat(); System.out.println( "value = " + decform.format(value) ); } }
On my computer (in the US) this program writes
Default Locale = en_US value = 123,456,789
The static method Locale.getDefault()
asks the virtual machine
for a reference to the default locale object it is using.
In the println()
statement that object's
toString()
method is implicitly used
to return a reference to the string
en_US
This specifies that the default language is English and the default country is US. Your computer might output a different locale code may format the number differently.
What do you think this program would print if it were running in Great Britain?